package com.example.order.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.order.ICouponService;
import com.example.order.constant.ShopCode;
import com.example.order.entity.Result;
import com.example.order.entity.TradeCoupon;
import com.example.order.exception.CastException;
import com.example.order.mapper.TradeCouponMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;

/**
 * @Author: songyahui
 * @Date: 2020/11/12 19:40
 * @Version 1.0
 */
@Component
@Service(interfaceClass = ICouponService.class)
public class CouponServiceImpl implements ICouponService {

    @Mapper
    private TradeCouponMapper couponMapper;

    @Override
    public TradeCoupon findOne(Long couponId) {
        if(couponId==null){
            CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
        }
        return couponMapper.selectByPrimaryKey(couponId);
    }


    @Override
    public Result updateCouponStatus(TradeCoupon coupon) {
        if(coupon==null||coupon.getCouponId()==null){
            CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
        }
        couponMapper.updateByPrimaryKey(coupon);
        return new Result(ShopCode.SHOP_SUCCESS.getSuccess(),ShopCode.SHOP_SUCCESS.getMessage());
    }
}
